<?php 

namespace app\controller\bossManager;

use app\service\AccountService;
use app\validate\UserPassValidate;
use share\service\UserBaseService;
use share\service\UserPassService;
use share\service\UserService;

class UserPassController extends WebBossController{

    public function initValidate(){
        $this->validate = new UserPassValidate();
    }

    /**
     * 设置临时密码
     */
    public function set_tmp_action(){
        $data = $this->getAESDecodeData();
        $param = $this->check('userPass',$data);
        $user = UserBaseService::getByUserId($param['userId']);
        if($user){
            UserPassService::setTempPass($user['id'],$param['password']);
            return self::ok([]);
        }
        else{
            return self::error('用户未找到');
        }

    }

    /**
     * 重置密码
     */
    public function reset_action(){
        $data = $this->getAESDecodeData();
        $param = $this->check('userPass',$data);
        $user = UserBaseService::getByUserId($param['userId']);
        if($user){
            UserPassService::upsertUserPass($user['id'],$param['password']);
            return self::ok([]);
        }
        else{
            return self::error('用户未找到');
        }
        return self::ok([]);
    }   
}
